<UserControl x:Class="GeniusTetris.BoardUC"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:pgo="clr-namespace:GeniusTetris" 
    Loaded="OnLoaded" Name="boardUC">
  <UserControl.Resources>
    <pgo:NumberToColorConverter x:Key="NumberToColor"/>
    <pgo:NumberToCharacterConverter x:Key="NumberToText"/>
    <Style TargetType="{x:Type Control}">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate>
            <Grid>
              <!--<Rectangle x:Name="rect" Margin="-0.1,-0.1,-0.1,-0.1"  Visibility="{Binding Visibility}"  
                         Fill="Violet"/>-->
              <Rectangle x:Name="rect" Margin="-0.1,-0.1,-0.1,-0.1"  Visibility="{Binding Visibility}"  
                       Fill="{Binding Number, Converter={StaticResource NumberToColor}}"/>
            <TextBlock Text="{Binding Number, Converter={StaticResource NumberToText}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
      <Setter Property="Focusable" Value="false"/>
    </Style>
    <Style x:Key="ToBlue" TargetType="{x:Type Rectangle}">
      <Style.Triggers>
        <EventTrigger RoutedEvent="Rectangle.Loaded">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>
                <ColorAnimation Storyboard.TargetProperty="(Rectangle.Fill).(LinearGradientBrush.GradientStops)[0].Color" To="Blue" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever"/>
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
      </Style.Triggers>
    </Style>
  </UserControl.Resources>
  <Viewbox Stretch="Uniform">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="15"/>
        <RowDefinition />
      </Grid.RowDefinitions>
      <TextBlock Grid.Row="0" FontSize="14" Foreground="Green" FontFamily="Courier New" 
                 Text="{Binding ElementName='boardUC', Path=PlayerName}" 
                   Visibility="{Binding ElementName='boardUC', Path=PlayerNamePanel}"/>
      <Border CornerRadius="5" Grid.Row="1" Width="200" Height="400" Background="Black">
        <Grid>
          <!-- uncomment to get a background on board-->
          <!--<Rectangle  RadiusX="3" RadiusY="3" StrokeThickness="0" VerticalAlignment="Stretch"  HorizontalAlignment="Stretch">
            <Rectangle.Fill>
              <LinearGradientBrush SpreadMethod="Repeat" MappingMode="Absolute" StartPoint="0,0" EndPoint="1,1">
                <LinearGradientBrush.Transform>
                  <ScaleTransform ScaleX="20" ScaleY="20"/>
                </LinearGradientBrush.Transform>
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FF222222" Offset ="0.499"/>
                <GradientStop Color="#FF222222" Offset ="0.501"/>
                <GradientStop Color="#FF222222" Offset ="1"/>
              </LinearGradientBrush>
            </Rectangle.Fill>
          </Rectangle>

          <Rectangle  RadiusX="3" RadiusY="3" Margin="0"  VerticalAlignment="Stretch"  HorizontalAlignment="Stretch">
            <Rectangle.Fill>
              <SolidColorBrush Color="#50FFFFFF" />
            </Rectangle.Fill>
          </Rectangle>-->
          <Grid Name="GridBoard" Visibility="Visible" ShowGridLines="False" >
            <!--  -->
          </Grid>
        </Grid>
      </Border>
      <Label Grid.Row="1"  Content="Invisible" Background="Gray" Foreground="White" FontSize="35" VerticalAlignment="Stretch"
             HorizontalAlignment="Stretch"
              VerticalContentAlignment="Center" 
              HorizontalContentAlignment="Center" 
              Visibility="{Binding ElementName='boardUC', Path=Invisibility}" />
      <Label Grid.RowSpan="2" Content="Game over !" Foreground="White" FontSize="35" VerticalAlignment="Stretch" 
             HorizontalAlignment="Stretch" 
              VerticalContentAlignment="Center" 
              HorizontalContentAlignment="Center"
             Visibility="{Binding ElementName='boardUC', Path=GameOver}" />
      <Grid Grid.Row="1" Visibility="{Binding ElementName='boardUC', Path=OffLine}">
        <Rectangle RadiusX="5" RadiusY="5" Fill="Gray"/>
        <Label Content="Offline" Foreground="White" FontSize="35" 
                VerticalContentAlignment="Center" 
                HorizontalContentAlignment="Center" 
                 />

      </Grid>
    </Grid>
  </Viewbox>
</UserControl>
